<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="true" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
    <script>
        var cxk="<%=request.getContextPath()%>";
    </script>
</head>
<body>
<div id="root">
    <i-button type="primary" @click="luRuCaiGouDan" style="margin: 20px">录入销售单</i-button>


    <modal  v-model="detailsModel" title="订单详情" width="850">
        <i-table :data="detailsData" :columns="detailsColumns"></i-table>
    </modal>


    <i-table style="margin: 20px" :data="orderData" :columns="orderColumns"  @on-row-dblclick="searchDetails">
        <%--<template slot="operation" slot-scope="{row}">--%>
            <%--<i-button type="info" icon="md-search" @click="searchDetails(row)">查看详情</i-button>--%>
        <%--</template>--%>
    </i-table>




    <Modal :mask-closable="false" v-model="luRuCaiGouDansss" title="销售" :mask-closable="false" width="90%"  @on-ok="gouMaiOnOk">
        <i-form :inline="true" :label-width="80">
            <form-item label="姓名">
                <i-input @on-change="onXingMing" @on-blur="onXingMings" v-model="namessssss"></i-input>
            </form-item>
            <form-item label="药店名称">
                <i-select :disabled="disabledsss" v-model="yaodian" style="width: 120px">
                    <i-option v-for="item in selevalue" :value="item.userid">{{item.mendian}}</i-option>
                </i-select>
            </form-item>
            <i-button type="primary" @click="gouMai">销售</i-button>
        </i-form>

        <i-table :data="datasasd" height="500" :columns="colun" border>
            <template slot="slotNumber" slot-scope="{row,index}">
                <%--<input :ref="row.drugsid" value="1"></input>--%>
                <input-number :min="1" :max="row.number" v-model="row.panNum" @on-change="onchangeNumber(row,index)"></input-number>
            </template>
            <template slot="caozuos" slot-scope="{row,index}">
                <i-button @click="ShanChu(row,index)">删除</i-button>
            </template>

        </i-table>
    </Modal>





    <Modal :mask-closable="false" :mask-closable="false" v-model="showHie" width="80%" title="销售" @on-ok="xiaoshouofuzhi">
        <Row  style="margin-top: 10px;margin-bottom: -20px">
            <i-col>
                <i-form :label-width="80" :inline="true">
                    <form-item label="编号">
                        <i-input v-model="id" type="number"></i-input>
                    </form-item>
                    <form-item label="药名">
                        <i-input v-model="name1" placeholder="名称"></i-input>
                    </form-item>
                    <form-item label="单位">
                        <i-select v-model="name2">
                            <i-option value="请选择">请选择</i-option>
                            <i-option v-for="item in companyList" :value="item.companyids" :key="item.id">{{item.companyids}}</i-option>
                        </i-select>
                    </form-item>
                    <form-item label="类别">
                        <i-select v-model="name3">
                            <i-option value="请选择">请选择</i-option>
                            <i-option v-for="item in categoryList" :value="item.drugsName" :key="item.id">{{item.drugsName}}</i-option>
                        </i-select>
                    </form-item>
                    <form-item label="供应商">
                        <i-select v-model="name4">
                            <i-option value="请选择">请选择</i-option>
                            <i-option v-for="item in supplierList" :value="item.companyName" :key="item.id">{{item.companyName}}</i-option>
                        </i-select>
                    </form-item>
                    <i-button type="primary" icon="ios-search" @click="select">查询</i-button>
                </i-form>
            </i-col>
        </Row>
        <i-table @on-selection-change="onchengaselection" :height="heights" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datas" :columns="colunmsss" border>
        </i-table>
        <page :total="totals" @on-change="onchenge" :page-Size="pageSize" show-sizer :page-size-opts="[4,6,8,12]" @on-page-size-change="onPageSizeChange"></page>


    </Modal>








</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            datas:[],
            datasasd:[],
            showhidess:false,
            asdadasd:1,
            yaodian:"",
            colunmsss:[
                {type:"selection",width:50},
                {title:"编号", key:"drugsid", sortable:true},
                {title:"药品名称", key:"drugsName", tooltip:true},
                {title:"价格/元", key:"prices"},
                {title:"数量", key:"number"},
                {title:"单位", key:"companyids"},
                {title:"供应商",key:"companyName"},
                {title:"类型", key:"drugsNametype"},
                {title:"功效", key:"effect", tooltip:true},
            ],
            colun:[
                {title:"编号", key:"drugsid", sortable:true},
                {title:"药品名称", key:"drugsName", tooltip:true},
                {title:"价格/元", key:"prices"},
                {title:"数量", key:"number",slot:"slotNumber"},
                {title:"单位", key:"companyids"},
                {title:"操作",slot:"caozuos"}
            ],
            luRuCaiGouDansss:false,
            heights:0,
            totals:0,
            pageNo:0,
            selevalue:[],
            pageSize:5,
            id:"",
            name1:"",
            drugModal:false,
            companyList:[],
            categoryList:[],
            supplierList:[],
            drugs:{},
            disabledsss:true,
            warehouseList:[],
            selectionselection:[],
            name2:"",
            name3:"",
            name4:"",
            showHie:false,
            namessssss:"",
            drgus:{},
            assss:0,
            orderData:[],
            orderColumns:[
                {title:"编号",key:"id"},
                {title:"订单号",key:"orideridid",
                    sortable: true
                },
                {title:"购买人",key:"goumairen"},
                {title:"购买公司",key:"mendinans"},
                {title:"购买时间",key:"goumaishijian",  sortable: true},
                // {title:"操作",slot:"operation"}
            ],
            detailsModel:false,
            detailsData:[],
            detailsColumns: [
                {title:"编号",key:"id"},
                {title:"药品编号",key:"drugsid",sortable: true},
                {title:"数量",key:"number",sortable: true},
                {title:"价格/元",key:"price"},
                {title:"合计/元",render(h,{row}){
                        return h("span",row.number*row.price)
                    }},
                {title:"购买时间",key:"atime",sortable: true}
            ],
            selectasdd:[]
        },
        methods:{
            onchenge(size){
                this.pageNo = size;
                this.select();
            },
            onPageSizeChange(size){
                this.pageSize = size;
                this.select();
            },
            select(){
                axios.get("/xiaoshouchaxun?id="+_this.id+"&name1="+_this.name1+"&pageNo="+_this.pageNo+"&pageSize="+_this.pageSize+"&name2="+this.name2+"&name3="+this.name3+"&name4="+this.name4).then(({data})=>{
                    _this.datas = data.obj.list;
                    _this.totals = data.obj.tatle;
                    _this.heights = data.obj.list.length * 48 + 40;
                })
            },
            searchCompany(){
                // 单位：瓶，盒
                axios.get(`${cxk}/zdrug/company`)
                    .then(({data})=>{
                        this.companyList=data.obj;
                    })

                //药品类型
                axios.get(`${cxk}/yaopinleixing`)
                    .then(({data})=>{
                        this.categoryList=data.obj;
                    })

                //查全部药品
                axios.get(`${cxk}/zdrug/searchAll`)
                    .then(({data})=>{
                        this.datas = data.obj;
                    })

                //给供应商下拉框赋值
                axios.get(`${cxk}/supplier/searchAll`)
                    .then(({data})=>{
                        this.supplierList = data.obj;
                    })

                //给仓库下拉框赋值
                axios.get(`${cxk}/kucun/searchWare`)
                    .then(({data})=>{
                        this.warehouseList=data.obj;
                    })
            },
            onchengaselection(selection){
                this.selectionselection = selection;
            },
            gouMai(){
                // if(this.selectionselection.length<=0){
                //     iview.Message.warning("请选中!");
                //     return;
                // }
                // for (let i = 0; i < this.selectionselection.length; i++) {
                //     if(this.selectionselection[i].number<=0){
                //         this.selectionselection.splice(i,1);
                //     }
                // }

                // this.datasasd;
                // this.selectionselection;
                // for (let i = 0; i < this.selectionselection.length; i++) {
                //     let a = this.selectionselection[i];
                //     let b = {};
                //     Object.assign(b,a)
                //     this.datasasd.push(b);
                // }

                this.showHie=true;
            },
            ShanChu(row,index){
                this.selectionselection.splice(index,1);
            },
            seras(){
                axios.get("/kuhu/select?pageNo=0&pageSize=999999999&name="+this.namessssss).then(({data})=>{
                    this.selevalue = data.obj.list;
                })
            },
            onXingMing(){
                this.yaodian = "";
                this.selevalue = [];
            },
            onXingMings(){
                if(this.namessssss!=null||this.namessssss!=""){
                    this.disabledsss = false;
                }
                this.seras();
            },
            onchangeNumber(row,index){
                // console.log(row.ysys)
                this.datasasd[index].panNum=row.panNum;
                // console.log(this.datasasd[index].panNum)
            },
            gouMaiOnOk(){
                 // console.log(this.$refs);
                 //    for(p in this.$refs){
                 //        console.log(p);
                 //        console.log(this.$refs[p].value);
                 //    }
                // this.datasasd[0].putNum = 2000;
                // console.log(this.datasasd[0].putNum)


                //namessssss
                //yaodian

                if(this.namessssss==null||this.namessssss==""){
                    iview.Message.warning("请填写名称!");
                    return;
                }
                if(this.yaodian==null||this.yaodian==""){
                    iview.Message.warning("请填写药店名称!");
                    return;
                }

                if(this.datasasd.length<=0){
                    iview.Message.warning("请填写数据!");
                    return;
                }

                let dindnid = 0;
                axios.get("/order?gouMaiRen="+this.namessssss+"&gouMaiGongSi="+this.yaodian+"&types=购买")
                    .then(({data})=>{
                        let a = {};
                        // dindnid = data.msg;
                        for (let i = 0; i < this.datasasd.length; i++) {
                            // console.log(this.datasasd[i].panNum)
                            Object.assign(this.datasasd[i],{Orderid:data.msg})
                            // console.log(this.datasasd[i].panNum)
                            console.log(this.datasasd[i])
                            this.assss = 1;
                            axios.post("/orderdingdan",this.datasasd[i]).then(({data})=>{
                                _this.select();
                            })
                        }
                        // axios.get("/zongjai?id="+data.msg).then(({data})=>{
                        //         iview.Message.warning("销售成功!")
                        // })
                        if(this.assss!=0){
                            this.searchAll();
                            iview.Message.warning("销售成功!")
                        }
                    })

            },
            xiaoshouofuzhi(){
                // if(this.datasasd.length>0){
                //     let a = 0;
                //     let j = 0;
                //     for (let i = 0; i < this.selectionselection.length; i++) {
                //         // if(this.datasasd[i].drugsid==this.selectionselection[i].drugsid){
                //         //     // console.log(this.datasasd[i].panNum);
                //         //     this.datasasd[i].panNum = this.datasasd[i].panNum+1;
                //         // }else{
                //         //     this.datasasd.push(this.selectionselection[i]);
                //         // }
                //         for (j = 0; j < this.datasasd.length; j++) {
                //             if(this.datasasd[i].drugsid==this.selectionselection[i].drugsid){
                //                 this.datasasd[i].drugsid.putNum +=1;
                //                 a = j;
                //             }
                //         }
                //         if(a!=j){
                //             this.datasasd.push(this.selectionselection[i]);
                //         }
                //     }
                // }else{
                //     this.datasasd= this.selectionselection;
                // }

                if (this.datasasd.length<=0){
                    for (let i = 0; i < this.selectionselection.length; i++) {
                        console.log(this.selectionselection[i])
                        this.selectionselection[i].panNum+=1;
                    }
                }
                this.datasasd= this.selectionselection;
            },
            luRuCaiGouDan(){
                this.namessssss = "";
                this.yaodian = "";
                this.datasasd = [];
                this.luRuCaiGouDansss = true;
            },
            searchAll(){
                let name1 = "";//购买人
                let name2 = "";//随机数
                let name3 = "";//购买公司id
                let name4 = "购买";//状态
                axios.get(`${cxk}/zOnInSearch/searchOrder?name1=${name1}&name2=${name2}&name3=${name3}&name4=${name4}`)
                    .then(({data})=>{
                        this.orderData = data.obj;
                    })
            },
            searchDetails(row){
                this.tetailsModel=true
                axios.post(`${cxk}/zOnInSearch/searchDetails?orderIds=${row.id}`)
                    .then(({data})=>{
                        this.detailsModel = true;
                        this.detailsData = data.obj;
                    })
            }
        },
        mounted(){
            this.onXingMing();
            this.select();
            this.searchAll();
            // this.selectType();
            this.searchCompany();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
